#!/bin/sh

[ -f "$XINITRC" ] && alias startx="startx $XINITRC"
# root privelages not required for some system commands
for command in mount umount sv pacman updatedb su shutdown poweroff reboot ; do
        alias $command="doas $command"
done; unset command

alias most="du -hsx * | sort -rh | head -10"

# Verbosity and settings that you pretty much just always are going to want.
alias \
        cp="cp -rpiv" \
        mv="mv -iv" \
        #rm="rm -vI" \
        bc="bc -ql" \
        mkd="mkdir -pv" \
        mkdir="mkdir -pv" \
        yt="youtube-dl --add-metadata -i" \
        yta="yt -x -f bestaudio/best" \
        ffmpeg="ffmpeg -hide_banner" \
        df="df -h" \
        du="du -h" \
        free='free -m' \

# Colorize commands when possible.
alias \
        ls="ls -hN --color=auto --group-directories-first" \
        grep="grep --color=auto" \
        diff="diff --color=auto" \
        ccat="highlight --out-format=ansi"

# These common commands are just too long! Abbreviate them.
alias \
        ka="killall" \
        g="git" \
        config="g --git-dir=$HOME/.local/src/dotfiles --work-tree=$HOME" \
        trem="transmission-remote" \
        YT="youtube-viewer" \ sdn="shutdown -h now" \
        e="$EDITOR" \
        v="$EDITOR" \
        myip='curl ipinfo.io/ip'\
        ports='doas netstat -tulanp' \
        p="pacman" \
        xi="doas xbps-install" \
        xr="doas xbps-remove -R" \
        xq="xbps-query" \
        z="zathura" \
        sha='shasum -a 256' \
        weather="curl wttr.in" \
        lsa="ls -A" \
        scim=sc-im \

# XDG Compliance
alias \
        vim="vim -u $XDG_CONFIG_HOME/vim/vimrc" \
        brave="brave; rm -r $HOME/.pki/ > /dev/null" \
        abook="abook --datafile $XDG_DATA_HOME/abook/addressbook" \

# Other useful aliases
alias \
        reload='source $XDG_CONFIG_HOME/zsh/.zshrc' \
        updshorts='shortcuts >/dev/null; source $XDG_CONFIG_HOME/shell/shortcutrc; source $XDG_CONFIG_HOME/shell/zshnameddirrc' \
        ref="updshorts; reload" \
        weath="getweather" \

alias clean="lsa | wc -l"


alias yta-aac="youtube-dl --extract-audio --audio-format aac "
alias yta-best="youtube-dl --extract-audio --audio-format best "
alias yta-flac="youtube-dl --extract-audio --audio-format flac "
alias yta-m4a="youtube-dl --extract-audio --audio-format m4a "
alias yta-mp3="youtube-dl --extract-audio --audio-format mp3 "
alias yta-opus="youtube-dl --extract-audio --audio-format opus "
alias yta-vorbis="youtube-dl --extract-audio --audio-format vorbis "
alias yta-wav="youtube-dl --extract-audio --audio-format wav "
alias ytv-best="youtube-dl -f bestvideo+bestaudio "


case $(uname -a) in
        *"MANJARO"*)
                true
        ;;
        *)
                alias mirror="doas $mirrorcmd -f 30 -l 30 --number 10 --verbose --save /etc/pacman.d/mirrorlist"
                alias mirrord="doas $mirrorcmd --latest 50 --number 20 --sort delay --save /etc/pacman.d/mirrorlist"
                alias mirrors="doas $mirrorcmd --latest 50 --number 20 --sort score --save /etc/pacman.d/mirrorlist"
                alias mirrora="doas $mirrorcmd --latest 50 --number 20 --sort age --save /etc/pacman.d/mirrorlist"
        ;;
esac

# alias "git commit"="git commit -S"
alias latin="words"

alias progs="(pacman -Qet; pacman -Qm) | sort -u"
alias orphans="pacman -Qdt"

alias "transmission-remote"="/usr/bin/transmission-remote -w $XDG_DATA_HOME/downloads/torrents -c $XDG_DATA_HOME/downloads/torrents-incomplete"
alias htp="pandoc $1.html -t latex -o test.pdf"


alias sx="/usr/bin/sx $XDG_CONFIG_HOME/x11/xinitrc"
alias picom="/usr/bin/picom --backend xrender"


alias ccaur="yes | yay -Sc; yay -Yc"
alias xpinst="yay -Qe"
alias hdu="dust --ignore-directory Pictures --ignore-directory Videos --ignore-directory Music --ignore-directory Documents --ignore-directory .cache/BraveSoftware --ignore-directory .config/BraveSoftware --ignore-directory .local/share/litecoin --ignore-directory .local/share/monero"
alias exi=exit
#alias lf=/usr/bin/lfrun
alias lf=lfub
# alias shcd="cd $(shfm)"
#alias cd="builtin cd; source $XDG_CONFIG_HOME/shell/promptless"
alias randname="tr -dc A-Za-z0-9 </dev/urandom | head -c 13 ; echo ''"
alias youtube-dl="yt-dlp"
alias chmox="chmod +x"

alias updateweb="rsync -rtvzP /home/will/.local/share/websites/williamlong.xyz/ root@williamlong.xyz:/var/www/williamlong"
alias updategopher="rsync -rtvzP /home/will/.local/share/websites/gopher-/williamlong.xyz/ root@williamlong.xyz:/var/gopher"

alias fixgpgdir="find ${XDG_DATA_DIR:-$HOME/.local/share}/gnupg -type f -exec chmod 600 {} \; && find ${XDG_DATA_DIR:-$HOME/.local/share}/gnupg -type d -exec chmod 700 {} \; "
alias movememes="mv ${XDG_CACHE_HOME:-$HOME/.cache}/newsimg/* ${XDG_DATA_HOME:-$HOME/.local/share}/pictures/memes/theos"

function domtohost() {
sed -e 's/^/0.0.0.0 /' $1 $2
}
function domtotab() {
for i in $(cat $1)
do
echo "/sbin/iptables -I INPUT -s $i -j DROP"
echo "/sbin/iptables -I OUTPUT -d $i -j REJECT"
done > $2
}

function tablock() {

for i in $(cat $1)
do
/sbin/iptables -I INPUT -s $i -j DROP
/sbin/iptables -I OUTPUT -d $i -j REJECT
done
}
function tsxlock() {

for i in $(cat $1)
do
/sbin/ip6tables -I INPUT -s $i -j DROP
/sbin/ip6tables -I OUTPUT -d $i -j REJECT
done
}

fmtforodysee() {
        ffmpeg -i $1 -c:v libx264 -preset slow -crf 18 -c:a aac -b:a 192k -pix_fmt yuv420p -movflags faststart $2
}

#alias slock="gpg-connect-agent --no-autostart reloadagent /bye && /usr/local/bin/slock"


fast() {
        tabbed -r 2 st -w '' -e dvtm
}
alias backup="rsync -avzP --delete  /home /media/mass/2tb/rsynchomebackups/2022-08-16"

alias la="ls -A"
alias mkd="mkdir"

alias getmost="cat ${XDG_CACHE_HOME:-$HOME/.cache}/zsh/history | awk 'BEGIN {FS=\"[ \t]+|\\\|\"} {print \$1}' | sort | uniq -c | sort -nr | head -25"
